﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteMain.Master" Inherits="System.Web.Mvc.ViewPage<TvGuide.UI.Models.ExternalVideoModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Home
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="Head" runat="server">
    <link href="/Content/admin.css" rel="stylesheet" type="text/css" />
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(function () {

        $('#preview').click(function () {
            var url = $('#urlbox').val();
            debugger;
            var pattyoutube = /^http[s]?:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=-?\w+)(?:\S+)?$/g;
           // var pattrutube = /^http[s]?:\/\/(?:www\.)?rutube.com\/video\/*./g;
           // if (!pattyoutube.test(url) && !pattrutube.test(url)) return;
            if (pattyoutube.test(url)) {
                if ($('#video-frame').length) {
                    $('#video-frame').remove();
                }

                var video_id = url.split("v=")[1];
                var ampersandPosition = video_id.indexOf('&');
                if (ampersandPosition != -1) {
                    video_id = video_id.substring(0, ampersandPosition);
                }

                var embedsrc = 'http://www.youtube.com/embed/' + video_id;
                var iframe = '<iframe id="video-frame" width="640" height="480" src="' + embedsrc + '" frameborder="0" allowfullscreen></iframe>';

                $('#embedurlbox').val(embedsrc);
                $('#external-video-content').append(iframe);
            }
            if (url.indexOf("http://rutube.ru/video") != -1) {
                var videoID = url.split('/')[4];
                var Src = 'http://video.rutube.ru/' + videoID;
                var iframe = '<body><object width="640" height="360"><param name="movie" value="' + Src + '"></param><param name="wmode" value="window"></param><param name="allowFullScreen" value="true"></param><embed src="' + Src + '" type="application/x-shockwave-flash" wmode="window" width="640" height="360"allowFullScreen="true" ></embed></object></body>';
                $('#embedurlbox').val(Src);
                $('#external-video-content').append(iframe);
            }

            
        });

    });
    </script>
</asp:Content>



<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="external-video-content">
    <% using (Html.BeginForm()) { %>
        <div>
            <%=Html.LabelFor(m => m.title)%>
            <%=Html.TextBoxFor(m => m.title)%>
            <%=Html.LabelFor(m => m.cat)%>
            <%=Html.EnumDropDownListFor(model => model.catEnum)%>
        </div>

        <div>
            <input type="text" name="urlbox" id="urlbox"/>
            <%=Html.HiddenFor(m => m.url, new { id = "embedurlbox" })%>

            <input id='preview' type='button' value="preview" />
            <input id='saveurl' type='submit' value="save" class="right"/>
        </div>


        <%if( Model != null && Model.newUrl != null) { %>
            <div>
                <label><%=Model.newUrl%></label>
            </div>
        <% } %> 
    <% } %>   
    </div>
</asp:Content>